package edu.whu.service.impl;

import edu.whu.dao.UserRepository;
import edu.whu.entity.User;
import edu.whu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserRepository repository;
    @Override
    @Cacheable(cacheNames = "user",key = "#username",condition = "#username!=null")
    public User getUser(String username) {
        return repository.selectByUsername(username);
    }

    @Override
    @CacheEvict(cacheNames = "user",key = "#userName")
    public void deleteUser(String userName) {
        repository.deleteById(userName);
    }
}
